<template>
  <div style="height: 100%">
    <el-row class="tac">
      <el-col :span="4">
        <el-menu
          :default-active="this.$route.path"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          router
        >
          <el-menu-item-group>
            <el-menu-item index="/info">个人信息</el-menu-item>
            <el-menu-item index="/History">我的订单</el-menu-item>
            <el-menu-item index="/order">我的预约</el-menu-item>
            <el-menu-item index="/house">我的房源</el-menu-item>
            <el-menu-item index="/commodity">我的商品</el-menu-item>

          </el-menu-item-group>
        </el-menu>
      </el-col>
      <el-col :span="20">
        <el-table
          :data="tableData"
          border
          style="width: 100%">
          <el-table-column
            fixed
            prop="date"
            label="订单日期"
            mid-width="25px">
          </el-table-column>
          <el-table-column
            prop="amount"
            label="订单金额"
            mid-width="25px">
          </el-table-column>
          <el-table-column
            prop="name"
            label="租客姓名"
            mid-width="25px">
          </el-table-column>
          <el-table-column
            fixed="right"
            label="操作"
            mid-width="25px">
            <template>
              <el-button @click="open" type="text" size="small">举报</el-button>
              <el-button  @click="open1"  type="text"  size="small">评论</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>

  </div>
</template>

<script>
export default {
  data () {
    return {
      activeName: 'first',
      tableData: [
        { date: '2021-04-04', amount: '3500元', name: '何同学' },
        { date: '2021-05-21', amount: '5000元', name: '丁同学' },
        { date: '2021-06-05', amount: '10500元', name: '张同学' }
      ]
    }
  },
  created () {
    this.initChargeHistory()
    this.initSpendHistory()
  },
  methods: {
    async initChargeHistory () {
      var userId = window.sessionStorage.getItem('userId')
      const res = await this.$http.get('/user/history/charge/' + userId)
      if (res.data.success === false) {
        this.$message.error(res.data.message)
      } else {
        this.chargeHistory = res.data.content
      }
    },
    open () {
      this.$prompt('请输入举报内容', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: '',
        inputErrorMessage: '邮箱格式不正确'
      }).then(({ value }) => {
        this.$message({
          type: 'success',
          message: '已提交举报信息'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消输入'
        })
      })
    },
    async initSpendHistory () {
      var userId = window.sessionStorage.getItem('userId')
      const res = await this.$http.get('/user/history/spend/' + userId)
      if (res.data.success === false) {
        this.$message.error(res.data.message)
      } else {
        this.spendHistory = res.data.content
      }
    },
    formatCharge (row, column) {
      return new Date(row.chargeTime).toLocaleString()
    },
    formatSpend (row, column) {
      return new Date(row.spendTime).toLocaleString()
    },
    open1 () {
      this.$prompt('请输入评论内容', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: '',
        inputErrorMessage: '邮箱格式不正确'
      }).then(({ value }) => {
        this.$message({
          type: 'success',
          message: '已完成评论 '
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消输入'
        })
      })
    }

  }
}
</script>

<style scoped>

</style>
